package com.zhengxing.jienci.content.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhengxing.jienci.common.pojo.CustomizePage;
import com.zhengxing.jienci.common.pojo.Tag;
import com.zhengxing.jienci.common.support.SimpleResponse;
import com.zhengxing.jienci.content.service.TagService;

/**
 * 
 * @ClassName: CategoryController
 * @Description: 资讯类别管理
 * @author yyh
 * @date 2020年10月31日
 *
 */
@RestController
@RequestMapping("/tag")
public class TagController {
	
	@Autowired
	private TagService tagService;
	
	/*********************************标签基本管理操作*********************************/
	/**
	 * 
	 * @author yyh
	 * @Title: query
	 * @Description: 标签查询
	 * @param @param tag
	 * @param @return
	 * @return List<Tag>
	 * @throws
	 */
	@GetMapping
	public List<Tag> query(Tag tag){
		return tagService.query(tag);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: pageQuery
	 * @Description: 标签分页查询
	 * @param @param page
	 * @param @param tag
	 * @param @return
	 * @return IPage<Tag>
	 * @throws
	 */
	@GetMapping("/page")
    public IPage<Tag> pageQuery(CustomizePage page, Tag tag) {
    	return tagService.pageQuery(page, tag);
    };
    
    /**
     * 
     * @author yyh
     * @Title: editById
     * @Description: 标签修改
     * @param @param tag
     * @param @return
     * @return SimpleResponse
     * @throws
     */
    @PutMapping
    public SimpleResponse editById(@RequestBody Tag tag) {
    	return tagService.editById(tag);
    };
    
    /**
     * 
     * @author yyh
     * @Title: deleteById
     * @Description: 标签删除
     * @param @param id
     * @param @return
     * @return SimpleResponse
     * @throws
     */
    @DeleteMapping("/{id}")
    public SimpleResponse deleteById(@PathVariable String id) {
    	return tagService.deleteById(id);
    };
	
    /**
     * 
     * @author yyh
     * @Title: insert
     * @Description: 标签添加
     * @param @param tag
     * @param @return
     * @return Object
     * @throws
     */
	@PostMapping
	public Object insert(@RequestBody Tag tag) {
		return tagService.insert(tag);
	}
	
	/*********************************标签与用户关系维护*********************************/
	
	/**
	 * 
	 * @author yyh
	 * @Title: userSelectionTag
	 * @Description: 用户选择标签1（废弃）
	 * @param @param userId
	 * @param @param tagId
	 * @param @return
	 * @return int
	 * @throws
	 */
	@PostMapping("/selection")
	public SimpleResponse userSelectionTag(@RequestParam(required = true,name = "tagId") String tagId) {
		return tagService.selectionTag(tagId);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: userSelectionTags
	 * @Description: 批量选择标签
	 * @param @param tagIds
	 * @param @return
	 * @return SimpleResponse
	 * @throws
	 */
	@PostMapping("/selections")
	public SimpleResponse userSelectionTags(String[] tagIds) {
		return tagService.selectionTags(tagIds);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: userCancelTag
	 * @Description: 用户取消所选中的标签
	 * @param @param tagId
	 * @param @return
	 * @return int
	 * @throws
	 */
	@PostMapping("/cancel")
	public SimpleResponse userCancelTag(@RequestParam(required = true,name = "tagId") String tagId) {
		return tagService.cancel(tagId);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: listTagByUserId
	 * @Description: 获取用户标签
	 * @param @return
	 * @return List<Tag>
	 * @throws
	 */
	@GetMapping("/listByUserId")
	public SimpleResponse listTagByUserId(){
		return tagService.listTagByUserId();
	}
}
